#include <glog/logging.h>
#include <pthread.h>
#include <sched.h>

void set_priority(pthread_t thread, int policy, int priority)
{
    sched_param sch_params;
    sch_params.sched_priority = priority;
    if (pthread_setschedparam(thread, policy, &sch_params)) {
        perror("Failed to set thread priority");
    }
}

void* worker(void*)
{
    while (true) { /* 做一些计算 */
    }
    return nullptr;
}

int main(int argc, char* argv[])
{
    google::SetStderrLogging(google::LogSeverity(FLAGS_minloglevel));
    google::InitGoogleLogging(argv[0]);
    pthread_t t;
    pthread_create(&t, nullptr, worker, nullptr);
    set_priority(t, SCHED_FIFO, 10); // 实时调度策略，优先级10
    pthread_join(t, nullptr);
    return 0;
}
